// iViewComponent/picker/index.js
Component({
    behaviors: ['wx://form-field'],
    /**
     * 组件的属性列表
     */
    properties: {
        title: {
            type: String
        },
        mode: {
            type: String
        },
        value: {
            type: Object,
            value: []
        },

        disable: {
            type: Boolean
        },
        placeholder: {
            type: String
        },
        range: {
            type: Array
        },
        key: {
            type: String
        },
        rangeValue: {
            type: Object
        },
        rangeShow: {
            type: String
        }

    },

    /**
     * 组件的初始数据
     */
    data: {

        defalutValue: []

    },

    /**
     * 组件的方法列表
     */
    methods: {
        handlePickerChange: function(e) {
            console.log('PickerChange', e.detail)
            this.setData({
                value: e.detail.value
            })

            // this.changeValue(e.detail.value)
        },
        changeValue(value = this.data.value) {
            // console.log('changeValue', value)
            //     // let _value
            // let param = { key: this.data.name, value: value }
            // if (this.data.mode === 'selector') {
            //     let p = this.data.range.find((item) => item.id == value)

            //     if (p) {
            //         this.setData({
            //             rangeShow: p.name
            //         })
            //     }

            // }
            // // else{

            // // }

            // this.triggerEvent('change', param);
            // console.log('changeValue', 'final', param)
        }
    },
    observers: {
        'value': function(value) {
            console.log('changeValue!!!', value)
            if (this.data.mode === 'selector') {
                let p = this.data.range.find((item, index) => item.id == value)
                console.log('p', p)
                if (p) {
                    this.setData({
                        rangeShow: p.name || ''
                    })
                }
            }
        }
    }
})